Skip to content

Extract triggers/conditions/services for non-primary entities#169441

Merged
abmantis merged 14 commits intodevfrom
automation_components_diag_entities2
Apr 29, 2026
Merged

Extract triggers/conditions/services for non-primary entities#169441
abmantis merged 14 commits intodevfrom
automation_components_diag_entities2

Conversation

@abmantis
Copy link
Copy Markdown
Member

Proposed change

Make get_triggers_for_target/get_conditions_for_target/get_services_for_target expose triggers/conditions/services with primary_entities_only=False when there are matching non-primary entities.
This keeps the existing behavior for when there are no indirect targets: all triggers/conditions/services are returned, regardless of the flag.

Implements #168101.

Depends on #169291.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (websocket_api) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of websocket_api can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign websocket_api Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@abmantis abmantis marked this pull request as draft April 29, 2026 10:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the websocket automation target lookups so triggers/conditions/services can be surfaced for indirectly-targeted non-primary (config/diagnostic) entities when the automation component explicitly opts in via primary_entities_only: false.

Changes:

  • Extend automation component lookup metadata to include primary_entities_only from the target description.
  • Expand target entity extraction to include non-primary entities, then selectively filter matches based on whether entities were indirectly referenced.
  • Add websocket API tests covering non-primary entity targeting and component descriptions using primary_entities_only: false.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
homeassistant/components/websocket_api/automation.py Implements primary_entities_only handling in automation component lookup and adjusts target extraction/matching logic.
tests/components/websocket_api/test_commands.py Adds non-primary entities to target fixtures and extends expected trigger/service results to validate the new behavior.
Comments suppressed due to low confidence (1)

homeassistant/components/websocket_api/automation.py:254

  • Apply entity-category filtering only to entities that were indirectly expanded (area/device/floor/label) so direct entity_id targets still match primary_entities_only=True components even when the same request also includes indirect targets.
    check_entity_category = len(extracted.indirectly_referenced) > 0
    entity_infos = entity_sources(hass)
    matched_components: set[str] = set()
    for entity_id in extracted.referenced | extracted.indirectly_referenced:
        if lookup_table.component_count == len(matched_components):

Comment thread homeassistant/components/websocket_api/automation.py Outdated
Comment thread tests/components/websocket_api/test_commands.py
@abmantis abmantis mentioned this pull request Apr 29, 2026
21 tasks
@abmantis abmantis marked this pull request as ready for review April 29, 2026 10:59
Copilot AI review requested due to automatic review settings April 29, 2026 10:59
@abmantis abmantis added this to the 2026.5.0b0 milestone Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the websocket automation target lookup so that triggers/conditions/services can be surfaced for indirectly targeted non-primary (config/diagnostic) entities when the automation component explicitly opts in via primary_entities_only: false, while preserving the “return everything” behavior for purely direct entity targets.

Changes:

  • Extend websocket automation component lookup to read primary_entities_only from target descriptions and apply entity-category filtering only when indirect targets are involved.
  • Extract target entities with primary_entities_only=False so indirectly referenced non-primary entities are available for matching.
  • Expand websocket API tests to cover non-primary entities in indirect targets for triggers/conditions and services.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
homeassistant/components/websocket_api/automation.py Adds primary_entities_only support to component matching and changes target extraction to include non-primary entities for indirect matching.
tests/components/websocket_api/test_commands.py Adds fixtures and assertions to validate trigger/condition/service lookup behavior with non-primary entities.

Comment thread homeassistant/components/websocket_api/automation.py Outdated
Comment thread homeassistant/components/websocket_api/automation.py Outdated
Comment thread tests/components/websocket_api/test_commands.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the websocket automation component lookup so triggers/conditions/services can be surfaced for indirect targets (device/area/label) even when the only matching entities are non-primary (config/diagnostic), if the component description explicitly opts in.

Changes:

  • Extend websocket automation component matching to respect a primary_entities_only flag from the component’s target description for indirectly referenced entities.
  • Always extract indirect targets with primary_entities_only=False, then apply per-component filtering during matching.
  • Expand websocket API command tests to cover indirect targets containing only non-primary entities and mixed direct+indirect targeting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/websocket_api/automation.py Adds per-component primary_entities_only handling and applies entity-category filtering only for indirect targets.
tests/components/websocket_api/test_commands.py Adds fixtures/entities and assertions to validate component exposure for non-primary indirect targets and direct+indirect combinations.

Comment thread homeassistant/components/websocket_api/automation.py
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@abmantis abmantis merged commit 8113734 into dev Apr 29, 2026
52 checks passed
@abmantis abmantis deleted the automation_components_diag_entities2 branch April 29, 2026 14:28
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surface battery triggers/conditions at floor/area/device/label level in trigger/condition picker

3 participants